﻿<?php
if (isset($_GET['id_article'])) 
{

	$sql = "SELECT * FROM `st_article` WHERE id_article=".$_GET['id_article'];
	$obj = new Mysql ();
	$result = mysql_query($sql);
	$row = mysql_fetch_object($result);

} else {

	$sql = "SELECT * FROM `st_article` ORDER BY date_add ASC ";
	$obj = new Mysql ();
	$result = mysql_query($sql);
}
// GET fournisseur
function getFournisseur($id){
	$sql = "SELECT * FROM st_att_fournisseur WHERE id_fournisseur=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	$tableau = array(); 
	if($num < 1){
		$tableau['nom'] = "Aucun";
			$tableau['prenom'] = "Aucun"; 
			$tableau['raison_social'] = "Aucun"; 
			$tableau['tel'] = "Aucun"; 
			$tableau['fax'] = "Aucun"; 
			$tableau['email'] = "Aucun"; 
	}else{
		$tableau['nom'] = $row['nom_fournisseur'];
			$tableau['prenom'] = $row['prenom_fournisseur']; 
			$tableau['raison_social'] = $row['raison_social']; 
			$tableau['tel'] = $row['tel_fournisseur']; 
			$tableau['fax'] = $row['fax_fournisseur']; 
			$tableau['email'] = $row['email_fournisseur']; 
	}
	return $tableau;
}
// GET Type Article
function getTypeArticle($id){
	$sql = "SELECT * FROM st_att_type_article WHERE id_type=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$type_article = "AUCUN";
	}else{
		$type_article = $row['nom_type'];
	}
	return $type_article;
}
// GET Lieu
function getLieu($id){
	$sql = "SELECT * FROM st_att_lieu_article WHERE id_lieu=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$lieu = "AUCUN";
	}else{
		$lieu = $row['nom_lieu'];
	}
	return $lieu;
}
// GET Unit
function getUnit($id){
	$sql = "SELECT * FROM st_att_unite_stockage WHERE id_unite_stockage=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$unit = "AUCUN";
	}else{
		$unit = $row['valeur'];
	}
	return $unit;
}
// unité stockage pr article
function getUnitArticle($id){
	$sql1 = "SELECT * FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result1 = mysql_query($sql1);
	$row1 = mysql_fetch_array($result1);
	$sql = "SELECT * FROM st_att_unite_stockage WHERE id_unite_stockage=".$row1['id_unite_stockage'];
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$unit = "AUCUN";
	}else{
		$unit = $row['valeur'];
	}
	return $unit;
}
// GET Unit
function getTypemonnaie($id){
	$sql = "SELECT * FROM st_att_monnaie WHERE id_monnaie=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$type = "AUCUN";
	}else{
		$type = $row['nom_monnaie'];
	}
	return $type;
}
// GET User
function getUser($id){
	$sql = "SELECT * FROM user_login WHERE id_login=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$email = "AUCUN";
	}else{
		$email = $row['email_login'];
	}
	return $email;
}
// GET Reference article
function getRefArticle($id){
	$sql = "SELECT * FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$ref = "AUCUN";
	}else{
		$ref = $row['ref_article'];
	}
	return $ref;
}
// GET Prix de vente article
function getPrixVenteArticle($id){
	$sql = "SELECT * FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$prix = 0;
	}else{
		$prix = $row['prix'];
	}
	return $prix;
}
// GET Designation article
function getDesignation($id){
	$sql = "SELECT * FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$designation = "AUCUN";
	}else{
		$designation = $row['designation'];
	}
	return $designation;
}
function getPhotoName($id){
	$sql = "SELECT * FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$ref = "AUCUN";
	}else{
		$ref = $row['photo_name'];
	}
	return $ref;
}
// get total stock
function getQtstock($id){
	$sql = "SELECT SUM(Quantite) as Quantite FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$stock_qte = "AUCUN";
	}else{
		$stock_qte = $row['Quantite'];
	}
	return $stock_qte;
}
// get total qt
function getTotQt($id){
	$sql = "SELECT Quantite as total_qt FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$designation = "AUCUN";
	}else{
		$designation = $row['total_qt'];
	}
	return $designation;
}

function getQtmin($id){
	$sql = "SELECT Qte_min FROM st_article WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$designation = "AUCUN";
	}else{
		$designation = $row['Qte_min'];
	}
	return $designation;
}
// GET Designation article
function getTotQtSortie($id){
	$sql = "SELECT SUM(Qte) as total_qt FROM st_attr_sortie WHERE id_article=".$id;
	$obj = new Mysql();
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
    $num = mysql_num_rows($result);
	if($num < 1){
		$qte = 0;
	}else{
		$qte = $row['total_qt'];
	}
	return $qte;
}



?>